﻿using ReflectionStudio.Core.Events;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TWPACK : ViewBase
    {
        #region ==dwWP===========
        public static readonly DependencyProperty dwWPProperty = DependencyProperty.Register("dwWP",
            typeof(DataRow), typeof(TWPACK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWPChanged));
        public DataRow dwWP
        {
            get
            {
                return (DataRow)GetValue(dwWPProperty);
            }
            set
            {
                SetValue(dwWPProperty, value);
            }
        }
        private static void OndwWPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWPACK;
            if (src != null)
            {
                src.dwWP = (DataRow)e.NewValue;
            }
        }
        #endregion
        

        public TWPACK()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MESSAGES += "WB2KO;";
            MV = new VWPACK();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            vwMaster.View.CurrentChanged += vwMaster_CurrentChanged;
        }

        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWP = dwMaster;
        }
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "WB2KO":
                    ((VWPACK)MV).LOADWPACK(msg);
                    vwMaster.View.MoveCurrentToFirst();  
                    break;
            }
        } 
    }
}